<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace plugins\portal_promotion;//Demo插件英文名，改成你的插件英文就行了
use cmf\lib\Plugin;

use plugins\portal_promotion\model\PortalPromotionModel;

//文章扩展字段
class PortalPromotionPlugin extends Plugin
{

    public $info = [
        'name'        => 'PortalPromotion',//Demo插件英文名，改成你的插件英文就行了
        'title'       => '文章扩展活动字段',
        'description' => '文章扩展活动字段',
        'status'      => 1,
        'author'      => 'guosheng1987@126.com',
        'version'     => '1.0.1',
        'demo_url'    => 'http://www.fenxiangmiao.com',
        'author_url'  => 'http://www.fenxiangmiao.com'
    ];

    public $hasAdmin = 0;//插件是否有后台管理界面

    // 插件安装
    public function install()
    {
        return true;//安装成功返回true，失败false
    }

    // 插件卸载
    public function uninstall()
    {
        return true;//卸载成功返回true，失败false
    }

    //实现的portal_admin_after_save_article钩子方法
    public function portalAdminAfterSaveArticle($param)
    {
        //文章保存后，更新活动扩展表
        //$config = $this->getConfig();
        /*
        $param          = [
            'is_add'  => true,
            'article' => $data['post']
        ];*/

        $post = $param['article'];

        $portalPromotionModel = new PortalPromotionModel();
        $portalPromotionPosted = $portalPromotionModel->where('post_id', $post['id'])->find();

        if(empty($portalPromotionPosted)) 
        {
            $portalPromotionModel->post_id = $post['id'];
            $portalPromotionModel->save();
        }
    
        //return $result;
    }

}